package com.ruoyi.business.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.BizDemo;
import com.ruoyi.business.service.IBizDemoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
    import com.ruoyi.common.core.page.TableDataInfo;
import java.util.Date;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 示例实体Controller
 *
 * @author ruoyi
 * @date 2025-08-09
 */
@Api(tags = "示例实体")
@RestController
@RequestMapping("/business/demo")
public class BizDemoController extends BaseController
{
    @Autowired
    private IBizDemoService bizDemoService;

/**
 * 分页查询示例实体
 */
@ApiOperation(value = "分页查询示例实体")
@ApiImplicitParams({
        @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "Integer", paramType = "query"),
        @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "Integer", paramType = "query")
})
@PreAuthorize("@ss.hasPermi('business:demo:list')")
@GetMapping("/list")
    public TableDataInfo list(@ApiIgnore BizDemo bizDemo)
    {
        startPage();
        List<BizDemo> list = bizDemoService.selectBizDemoList(bizDemo);
        return getDataTable(list);
    }

    /**
     * 查询所有示例实体
     */
    @ApiOperation(value = "查询所有示例实体")
    // 筛选对象参数实际需要的属性    如下配置接口文档就只会显示 searchValue、createTime 两个参数   请根据实际情况调整
    @ApiOperationSupport(includeParameters = {"searchValue", "createTime"})
    @PreAuthorize("@ss.hasPermi('business:demo:query')")
    @GetMapping("/all")
    public R<List<BizDemo>> all(BizDemo bizDemo)
    {
        List<BizDemo> list = bizDemoService.selectBizDemoList(bizDemo);
        return R.ok(list);
    }

    /**
     * 根据 ID 批量查询示例实体
     */
    @ApiOperation(value = "根据 ID 批量查询示例实体")
    @ApiOperationSupport(includeParameters = {"ids"})
    @PreAuthorize("@ss.hasPermi('business:demo:query')")
    @GetMapping("/list/ids")
    public R<List<BizDemo>> listByIds(BizDemo bizDemo)
    {
        List<BizDemo> list = bizDemoService.selectBizDemoByIds(bizDemo.getIds());
        return R.ok(list);
    }

    /**
     * 导出示例实体列表
     */
    @ApiOperation(value = "导出示例实体列表")
    @ApiOperationSupport(includeParameters = {"searchValue", "createTime"})
    @PreAuthorize("@ss.hasPermi('business:demo:export')")
    @Log(title = "示例实体", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@ApiIgnore HttpServletResponse response, BizDemo bizDemo)
    {
        List<BizDemo> list = bizDemoService.selectBizDemoList(bizDemo);
        ExcelUtil<BizDemo> util = new ExcelUtil<BizDemo>(BizDemo.class);
        util.exportExcel(response, list, "示例实体数据");
    }

    /**
     * 获取示例实体详细信息
     */
    @ApiOperation(value = "获取示例实体详细信息")
    @ApiImplicitParam(name = "id", value = "ID", dataType = "Integer", paramType = "path")
    @PreAuthorize("@ss.hasPermi('business:demo:query')")
    @GetMapping(value = "/{id}")
    public R<BizDemo> getInfo(@PathVariable("id") Long id)
    {
        return R.ok(bizDemoService.selectBizDemoById(id));
    }

    /**
     * 查询单条示例实体
     */
    @ApiOperation(value = "查询单条示例实体")
    @ApiOperationSupport(includeParameters = {"searchValue", "createTime"})
    @PreAuthorize("@ss.hasPermi('business:demo:query')")
    @GetMapping("/one")
    public R<BizDemo> one(BizDemo bizDemo)
    {
        BizDemo bizDemoResult = bizDemoService.selectBizDemoOne(bizDemo);
        return R.ok(bizDemoResult);
    }

    /**
     * 新增示例实体
     */
    @ApiOperation(value = "新增示例实体")
    @PreAuthorize("@ss.hasPermi('business:demo:add')")
    @Log(title = "示例实体", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@RequestBody BizDemo bizDemo)
    {
        bizDemo.setCreateBy(getLoginUser().getUser().getNickName());
        bizDemo.setCreateTime(new Date());

        return bizDemoService.save(bizDemo) ? R.ok() : R.fail();
    }

    /**
     * 修改示例实体
     */
    @ApiOperation(value = "修改示例实体")
    @PreAuthorize("@ss.hasPermi('business:demo:edit')")
    @Log(title = "示例实体", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@RequestBody BizDemo bizDemo)
    {
        bizDemo.setUpdateBy(getLoginUser().getUser().getNickName());
        bizDemo.setUpdateTime(new Date());

        return bizDemoService.updateById(bizDemo) ? R.ok() : R.fail();
    }

    /**
     * 删除示例实体
     */
    @ApiOperation(value = "删除示例实体")
    @ApiImplicitParam(name = "ids", value = "逗号分隔的 ID 字符串", dataType = "String", paramType = "path")
    @PreAuthorize("@ss.hasPermi('business:demo:remove')")
    @Log(title = "示例实体", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@PathVariable Long[] ids)
    {
        return bizDemoService.removeByIds(Arrays.asList(ids)) ? R.ok() : R.fail();
    }
}
